home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / trigrp / colormap.c < prev    next >
C/C++ Source or Header  |  1992-02-23  |  917b  |  54 lines

  1. #include <stdio.h>
  2. #include <color.h>
  3.  
  4. static ColorA  builtin[] =     {
  5.     {.8, .6, .2, .5},
  6.     {.2, .8, .6, .5},
  7.     {.6, .2, .8, .5}};
  8.     
  9. static ColorA *colormap = NULL;
  10. static int cnt;
  11.  
  12. int
  13. readcmap(cmapfname)
  14. char *cmapfname;
  15. {
  16.     FILE *fp;
  17.     int size = 256;
  18.     
  19.     if (cmapfname == NULL)    goto ZXCV;
  20.     
  21.     fp = fopen(cmapfname,"r");
  22.     if (fp == NULL)        goto ZXCV;
  23.     
  24.     cnt = 0;
  25.     colormap = (ColorA *) malloc(sizeof(ColorA) * size);
  26.     
  27.     while (fscanf(fp, "%f%f%f%f", 
  28.         &colormap[cnt].r, &colormap[cnt].g, &colormap[cnt].b, &colormap[cnt].a) == 4)
  29.         {
  30.         cnt++;
  31.         if (cnt > size)    {
  32.             size *= 2;
  33.             colormap = (ColorA *) realloc(colormap, sizeof(ColorA) * size);
  34.             if (colormap == NULL) goto ZXCV;
  35.             }
  36.         }
  37.     return(cnt);
  38. /*
  39.     fprintf(stderr,"readcmap: %d entries read\n",cnt);
  40. */
  41. ZXCV:
  42.     colormap = builtin;
  43.     cnt = 3;
  44.     return(cnt);
  45. }
  46.  
  47. ColorA
  48. GetCmapEntry(n)
  49. int n;
  50. {
  51.     if (n < 0  || n > cnt)    return(colormap[0]);
  52.     else return (colormap[n]);
  53. }
  54.